/* $Id:line_change.cc jjs $ */
/*
   Copyright (C) 2007 by Jurjen Stellingwerff <jurjen@stwerff.xs4all.nl>
   Part of the Moros Project http://moros.sourceforge.net/

   This program is free software; you can redistribute it and/or modify
   it under the terms of the GNU General Public License.
   This program is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY.

   See the COPYING file for more details.
*/

#define DEBUG_ROUTINE "line_change"

#include "line_change.h"
#include "moros.h"
#include "../general/log.h"


line_change::line_change(BaseObjectType* cobject, const Glib::RefPtr<Gnome::Glade::Xml> refGlade)
: Gtk::Dialog(cobject), m_refGlade(refGlade) {
	m_refGlade->get_widget("line_cancel", line_cancel);
	m_refGlade->get_widget("line_apply", line_apply);
	m_refGlade->get_widget("line_label", line_label);
	m_refGlade->get_widget("line_text", line_text);

	line_apply->signal_clicked().connect(sigc::mem_fun(*this, &line_change::clicked_apply));
	line_cancel->signal_clicked().connect(sigc::mem_fun(*this, &line_change::clicked_cancel));
}

line_change::~line_change() {
}

void line_change::clicked_cancel() {
    hide();
}

void line_change::clicked_apply() {
    signal_apply.emit(line_text->get_text());
    hide();
}

line_change *line_change_dial=NULL;

void init_line_change() {
    dbg_calls("init_line_change");
    refXml->get_widget_derived("line_change", line_change_dial);
    if (!line_change_dial) dbg_fatal("Could not open line_change page");
}

void line_changer(std::string label, std::string line, sigc::signal<void, std::string> signal_apply) {
    if (!line_change_dial) dbg_fatal("Line_change page not initialized");
    line_change_dial->signal_apply=signal_apply;
    line_change_dial->line_label->set_text(label);
    line_change_dial->line_text->set_text(line);
    line_change_dial->present();
    line_change_dial->line_text->grab_focus();
}
